﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Cinser.DataTranslate
{
    /// <summary>
    /// 单表移植设置
    /// </summary>
    public class TranslateTableSettings
    {
        TaskManager.TaskBase taskInstance;
        /// <summary>
        /// 添加或者更新前调用的委托
        /// </summary>
        public DataTableDelegate BeforeAddOrUpdate;

        /// <summary>
        /// 正准备更新前调用的委托
        /// </summary>
        public DataRowDelegate AddOrUpdating;

        /// <summary>
        /// 更新完成后调用的委托
        /// </summary>
        public ExceptionDelegate AddOrUpdated;

        string sourceTbName, targetTbName;
        Dictionary<string, string> columnsMapping;
        List<string> keysColumns;

        /// <summary>
        /// 目标数据库表名
        /// </summary>
        public string TargetTbName
        {
            get
            {
                if (string.IsNullOrEmpty(targetTbName))
                    targetTbName = sourceTbName;
                return targetTbName;
            }
            set { targetTbName = value; }
        }


        public TaskManager.TaskBase TaskInstance
        {
            get { return taskInstance; }
            set { taskInstance = value; }
        }

        /// <summary>
        /// 源数据库表名
        /// </summary>
        public string SourceTbName
        {
            get
            {
                if (string.IsNullOrEmpty(sourceTbName))
                    sourceTbName = targetTbName;
                return sourceTbName;
            }
            set { sourceTbName = value; }
        }

        /// <summary>
        /// 唯一列组
        /// </summary>
        public List<string> KeysColumns
        {
            get { return keysColumns; }
            set { keysColumns = value; }
        }

        /// <summary>
        /// 源表与目标表列名对应关系
        /// </summary>
        public Dictionary<string, string> ColumnsMapping
        {
            get { return columnsMapping; }
            set { columnsMapping = value; }
        }

        public TranslateTableSettings(string tbName, TaskManager.TaskBase taskInstance)
        {
            this.SourceTbName = tbName;
            ColumnsMapping = new Dictionary<string, string>();
            KeysColumns = new List<string>();
            this.TaskInstance = taskInstance;
        }
    }
}
